<?php

namespace App\Http\Controllers;

use Houdunwang\WeChat\WeChat;
use Illuminate\Http\Request;
use Modules\Wx\Entities\WeConfig;

class WechatController extends Controller
{
    //
    public function handle(WeConfig $weConfig)
    {
        $this->valid($weConfig);
        //测试接收微信消息
        WeChat::content('Content');
        //消息管理模块
        $instance =WeChat::instance('message');
        //判断是否是文本消息
        if ($instance->isTextMsg())
        {
            //向用户回复消息
            return $instance->text('后盾人收到你的消息了...:' . $instance->Content);
        }

    }

    protected function valid($weConfig){
        //获取wechat.php配置文件的内容
        $config = include base_path('config') . '/wechat.php';
        //获取数据库中的微信配置数据
        $weConfig = $weConfig->pluck('value','name')->toArray();
        //将两个数组合并
        $config = array_merge($config,$weConfig);
        WeChat::config($config)->valid();
    }



}
